var t, e = require("../../@babel/runtime/helpers/interopRequireDefault"),
  a = e(require("../../@babel/runtime/regenerator")),
  i = e(require("../../@babel/runtime/helpers/asyncToGenerator")),
  base = require("../../base.js"),
  o = getApp();
var list = require("../../datas/list.js");
Page({
  data: {
    douyin: base.IMGPATH + "but_douyin.png",
    icons: {
      icon01: base.IMGPATH + "ic_luck.png",
      icon02: base.IMGPATH + "qinggan.png",
      icon03: base.IMGPATH + "quwei2.png",
      icon04: base.IMGPATH + "xingge.png",
      icon05: base.IMGPATH + "ic_hot.png",
      back: base.IMGPATH + "back_left_01.png",
      back2: base.IMGPATH + "back_left_02.png"
    },
    keyWord: "",
    pageNumber: 1,
    pageSize: 10,
    questionCategory: "",
    list: [],
    status: !1,
    topDistance: 0,
    backHeight: 0,
    backWidth: 0,
    leftDistance: 0,
    lineHeight: "",
    activeTopStatus: !1,
    paddingHeight: 0
  },
  onLoad: function (t) {
    var e = this,
      i = o.globalData.headerBtnPosi,
      n = o.globalData.winWidth,
      r = 2 * o.globalData.statusBarHeight,
      s = n - i.right,
      c = i.height,
      u = 2 * c,
      g = 2 * c + 36;
    wx.showLoading({
      title: "加载中"
    });
    var l = decodeURIComponent(t.cate);
    var category = decodeURIComponent(t.category);
    this.setData({
      topDistance: r,
      lineHeight: g,
      paddingHeight: g + 2 * r,
      leftDistance: s,
      backWidth: u,
      backHeight: c,
      questionCategory: category
    }, function () {
      wx.setNavigationBarTitle({
        title: l
      }), e.fetchData();
    });
  },
  fetchData: (t = (0, i.default)(a.default.mark(function t() {
    var e, i, n, o, c, u, g, l, d, p;
    return a.default.wrap(function (t) {
      for (;;) switch (t.prev = t.next) {
        case 0:
          return e = this.data, i = e.keyWord, n = e.pageNumber, o = e.pageSize, c = e.questionCategory,
            u = e.list, g = e.status, t.next = 3, (0, base.ajax)({
              url: "/api/testQuestion/getPager",
              data: {
                keyWord: i,
                pageSize: o,
                pageNumber: n,
                questionCategory: c
              }
            });

        case 3:
          if (!t.sent) {
            t.next = "end";
            wx.hideLoading();
            break;
          }
          if (l = t.sent, wx.hideLoading(), l.code) {
            t.next = 15;
            break;
          }
          if (!l.data) {
            t.next = 9;
            d = list.filter((e) => e.category_id == c);
            wx.hideLoading();
            break;
          }
          if ((d = l.data.data).length) {
            t.next = 9;
            break;
          }
          return t.abrupt("return");

        case 9:
          for (d.length >= o ? (n++, g = !0) : g = !1, p = 0; p < d.length; p++) d[p].reads = (0,
            base.getRandomNumberByRange)(1e3, 1e5);
          u = u.concat(d), this.setData({
            pageNumber: n,
            list: u,
            status: g
          }), t.next = 16;
          break;

        case 15:
          this.setData({
            status: !1
          });

        case 16:
          return t.abrupt("return", g);

        case 17:
        case "end":
          return t.stop();
      }
    }, t, this);
  })), function () {
    return t.apply(this, arguments);
  }),
  bindscroll: function (t) {
    var e = this.data,
      a = e.topDistance,
      i = e.activeTopStatus,
      n = t.detail.scrollTop;
    n > 2 * a && !i && this.setData({
      activeTopStatus: !0
    }), n <= 2 * a && i && this.setData({
      activeTopStatus: !1
    });
  },
  lowerScroll: function () {
    this.data.status && this.fetchData();
  },
  jumpDetail: function (t) {
    var e = t.currentTarget.dataset.id;
    if (!e) throw new Error("detail id 缺失");
    wx.navigateTo({
      url: "/pages/detail/index?id=" + e
    });
  },
  backHandle: function () {
    wx.navigateBack({
      delta: 1
    });
  },
  onShareAppMessage: function (t) {
    var e = this.data.questionCategory,
      a = "/pages/list/index?cate=" + encodeURIComponent(e),
      i = "";
    return "趣味测试" == e ? i = icons.icon03 : "爱情测试" == e ? i = icons.icon02 : "缘分测试" == e ? i = icons.icon01 : "性格测试" == e && (i = icons.icon04), {
      title: e,
      imageUrl: i,
      path: a
    };
  }
});